package com.rem.cloudalibaba.service.fallback;

import com.rem.cloudalibaba.entity.CommonResult;
import com.rem.cloudalibaba.entity.Product;
import com.rem.cloudalibaba.service.ProductService;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 能够显示异常信息的处理工厂
 *
 * @author Rem
 * @date 2021-08-09
 */
@Component
public class ProductServiceFallBackFactory implements FallbackFactory<ProductService> {

    @Override
    public ProductService create(Throwable throwable) {

        return new ProductService() {
            @Override
            public CommonResult<Product> getProduct(Integer id) {
                //打印异常
                throwable.printStackTrace();
                Product product = new Product();
                product.setPid(-1);
                return CommonResult.error(product);
            }

            @Override
            public CommonResult<Product> redStock(Integer id, Integer num) {
                return CommonResult.error();
            }

            @Override
            public CommonResult<String> test(Integer id) {
                return CommonResult.error();
            }

        };
    }

}
